<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link th:href="@{/erp/assets/css/bootstrap.min.css}" rel="stylesheet"/>
    <link rel="stylesheet" th:href="@{/erp/css/style.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome.min.css}"/>
    <link rel="stylesheet" th:href="@{/erp/Widget/zTree/css/zTreeStyle/zTreeStyle.css}" type="text/css">
    <link th:href="@{/erp/Widget/icheck/icheck.css}" rel="stylesheet" type="text/css"/>
    <!--[if IE 7]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/font-awesome-ie7.min.css}"/>
    <![endif]-->
    <!--[if lte IE 8]>
    <link rel="stylesheet" th:href="@{/erp/assets/css/ace-ie.min.css}"/>
    <![endif]-->
    <script th:src="@{/erp/js/jquery-1.9.1.min.js}"></script>
    <script th:src="@{/erp/assets/js/bootstrap.min.js}"></script>
    <script th:src="@{/erp/assets/js/typeahead-bs2.min.js}"></script>
    <!-- page specific plugin scripts -->
    <script th:src="@{/erp/assets/js/jquery.dataTables.min.js}"></script>
    <script th:src="@{/erp/assets/js/jquery.dataTables.bootstrap.js}"></script>
    <script th:src="@{/erp/assets/layer/layer.js}" type="text/javascript"></script>
    <script th:src="@{/erp/assets/laydate/laydate.js}" type="text/javascript"></script>
    <script type="text/javascript" th:src="@{/erp/Widget/zTree/js/jquery.ztree.all-3.5.min.js}"></script>
    <title>物流公司信息</title>
</head>
<body>
<div class=" page-content clearfix">
    <div id="products_style">
        <div class="search_style">
            <form>
                <ul class="search_content clearfix">
                    <li><label class="l_f">物流公司名称</label><input id="logisticsallbyName" name="logisticsName" type="text"
                                                                class="text_add" placeholder="输入物流公司名称"
                                                                style=" width:250px"/></li>

                    <li style="width:90px;">
                        <button type="button" class="btn_search" id="selectbyname"><i class="icon-search"></i>查询
                        </button>
                    </li>
                </ul>
            </form>
        </div>
        <div class="border clearfix">
       <span class="l_f">
        <button id="logistic_add" class="btn btn-warning"><i class="icon-plus"></i>添加物流公司</button>
       </span>

        </div>

        <table class="table table-striped table-bordered table-hover" id="sample-table">
            <thead>
            <tr>
                <th width="150px" style='display:none'>物流公司ID</th>
                <th width="150px">物流公司编号</th>
                <th width="150px">物流公司名称</th>
                <th width="100px">负责人</th>
                <th width="180px">联系方式</th>
                <th width="200px">运营区域</th>
                <th width="180px">加入时间</th>

                <th width="150px">价格(元/每吨)</th>
                <th width="150px">操作</th>
            </tr>
            </thead>
            <tbody>


            </tbody>
        </table>
    </div>
</div>
</div>
</div>


<!--添加物流公司图层-->
<form action="/products/addProduct" method="post" class="form form-horizontal" id="form-article-add">
    <div class="add_menber" id="add_menber_style" style="display:none">

        <ul class=" page-content">

            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red"></span>*公司名称：</label>
                <div class="formControls ">
                    <input type="text" onchange="logisticszc(this)" class="input-text" value="" placeholder="" id="logisticsName" name="公司名称">
                </div>
            </div>


            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red"></span>*负责人：</label>
                <div class="formControls ">
                    <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="principal" name="负责人">
                </div>
            </div>

            <div class="Operate_cont clearfix">
                <label class="form-label" ><span class="c-red"></span>*手机号码：</label>
                <div class="formControls ">
                    <input type="text" onchange="phone(this)" class="phone" value="" placeholder="" id="logisticsContact" name="手机号码">
                </div>
            </div>

            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red"></span>*运营区域：</label>
                <div class="formControls ">
                    <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="area" name="运营范围">
                </div>
            </div>

            <div class="Operate_cont clearfix">
                <label class="form-label"><span class="c-red"></span>*价格(元/每吨)：</label>
                <div class="formControls ">
                    <input type="text" onchange="money(this)" class="moneyxx" value="" placeholder="" id="price" name="价格(每吨)">
                </div>
            </div>

            <div class="Operate_cont clearfix">
                <label class="form-label">*备注：</label>
                <div class="formControls">
                    <textarea name="" rows="" maxlength="120" class="textarea" id="remarks" placeholder="说点什么...最少输入10个字符"
                              datatype="*10-100" dragonfly="true" nullmsg="备注不能为空！"
                    ></textarea>

                </div>
            </div>

            <div class=""/>
            <div class="" style=" text-align:center"/>
        </ul>
    </div>
</form>
>

</div>
</div>
</div>
</div>
</div>
<!--编辑属性图层-->
<div class="edit_menber" id="edit_menber_style" style="display:none">

    <ul class=" page-content">
        <div class="Operate_cont clearfix" style="display:none">
            <label class="form-label"><span class="c-red"></span>公司ID：</label>
            <div class="formControls ">
                <input type="text"  class="input-text" value="" placeholder="" id="logisticsIdbj" name="公司名称">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>公司名称：</label>
            <div class="formControls ">
                <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="logisticsNamebj" name="公司名称">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>负责人：</label>
            <div class="formControls ">
                <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="principalbj" name="负责人">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>手机号码：</label>
            <div class="formControls ">
                <input type="text" onchange="phone(this)" class="phone" value="" placeholder="" id="logisticsContactbj"
                       name="手机号码">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>运营区域：</label>
            <div class="formControls ">
                <input type="text" onchange="writegz(this)" class="input-text" value="" placeholder="" id="areabj" name="运营区域">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label"><span class="c-red"></span>价格(元/每吨)：</label>
            <div class="formControls ">
                <input type="text" onchange="money(this)" class="moneyxx" value="" placeholder="" id="pricebj" name="价格(每吨)">
            </div>
        </div>
        <div class="Operate_cont clearfix">
            <label class="form-label">备注：</label>
            <div class="formControls">
                    <textarea name="" maxlength="120" rows="" id="remarksbj" class="textarea" placeholder="说点什么...最少输入10个字符"
                              datatype="*10-100"
                              dragonfly="true" nullmsg="备注不能为空！"
                              >这是很重要的事情！！！！！</textarea>

            </div>
        </div>

    </ul>
</div>

<script type="text/javascript" th:src="@{/js/regularExpression.js}"></script>
</body>
</html>
<script>


    /*物流公司-添加*/
    $('#logistic_add').on('click', function () {

        layer.open({
            type: 1,
            title: '添加物流公司',
            maxmin: true,
            shadeClose: true, //点击遮罩关闭层
            area: ['600px', ''],
            content: $('#add_menber_style'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $(".add_menber input[type$='text']").each(function (n) {
                    if ($(this).val() == "") {

                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        });
                        num++;
                        return false;
                    }
                });

                if (num > 0) {
                    return false;
                } else {
                    $.ajax({
                        data: {
                            "logisticsName": document.getElementById('logisticsName').value
                            , "principal": document.getElementById('principal').value
                            , "logisticsContact": document.getElementById('logisticsContact').value
                            , "area": document.getElementById('area').value
                            , "price": document.getElementById('price').value
                            , "remarks": document.getElementById('remarks').value
                        },
                        type: 'post',
                        dataType: 'josn',
                        url: '/logisticsxx/add',
                        success: function (data) {
                            alert(data);
                            if(!data.rs){
                                layer.msg(data.msg,{icon:2,time:2000})
                            }
                        }
                    });
                    layer.alert('添加成功！', {
                        title: '提示框',
                        icon: 1,
                    });
                    parent.layer.close(index);
                    window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
                }
            }
        });
    });


    /*物流公司信息-编辑*/
    function member_edit(e) {
        var id = $(e).parent().parent().children("td:eq(0)").text();
        document.getElementById('logisticsIdbj').value = $(e).parent().parent().children("td:eq(0)").text();
        document.getElementById('logisticsNamebj').value = $(e).parent().parent().children("td:eq(2)").text();
        document.getElementById('principalbj').value = $(e).parent().parent().children("td:eq(3)").text();
        document.getElementById('logisticsContactbj').value = $(e).parent().parent().children("td:eq(4)").text();
        document.getElementById('areabj').value = $(e).parent().parent().children("td:eq(5)").text();
        document.getElementById('pricebj').value = $(e).parent().parent().children("td:eq(7)").text();

        $.ajax({
            data: {"logisticsId": id},
            type: 'post',
            dataType: 'json',
            url: '/logisticsxx/findbyid',
            success: function (data) {
                console.log(data.rs);
                if(data.rs) {
                    console.log("返回成功");
                    console.log(data);
                    var d = data.data;
                    document.getElementById('remarksbj').value = d;
                }else {
                    layer.msg(data.msg,{icon:2,time:2000});
                }
            }
        });
        console.log(e);
        layer.open({
            type: 1,
            title: '修改物流公司信息',
            maxmin: true,
            shadeClose: false, //点击遮罩关闭层
            area: ['600px', ''],
            content: $('#edit_menber_style'),
            btn: ['提交', '取消'],
            yes: function (index, layero) {
                var num = 0;
                var str = "";
                $(".edit_menber input[type$='text']").each(function (n) {
                    if ($(this).val() == "") {

                        layer.alert(str += "" + $(this).attr("name") + "不能为空！\r\n", {
                            title: '提示框',
                            icon: 0,
                        });
                        num++;
                        return false;
                    }
                });
                if (num > 0) {
                    return false;
                } else {
                    $.ajax({
                        data: {
                            "logisticsId": document.getElementById('logisticsIdbj').value
                            , "logisticsName": document.getElementById('logisticsNamebj').value
                            , "principal": document.getElementById('principalbj').value
                            , "logisticsContact": document.getElementById('logisticsContactbj').value
                            , "area": document.getElementById('areabj').value
                            , "price": document.getElementById('pricebj').value
                            , "remarks": document.getElementById('remarksbj').value
                        },
                        type: 'post',
                        dataType: 'josn',
                        url: '/logisticsxx/update',
                        success: function (data) {
                            alert(data);
                            if(!data.rs){
                                layer.msg(data.msg,{icon:2,time:2000})
                            }
                        }
                    });

                    layer.alert('修改成功！', {
                        title: '提示框',
                        icon: 1,
                    });
                    layer.close(index);
                    window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
                }
            }
        });
    }

    //查询
    jQuery(function ($) {
        var oTable1 = $('#sample-table').dataTable({
            searching: false,
            serverSide: true,
            ajax: {
                url: '/logisticsxx/findAll',
                type: 'post',
                data: function (d) {
                    var data = $('form').serialize();
                    var searchParame = {
                        start: d.start / 10 + 1,
                        length: d.length,
                    };
                    data = data + '&' + $.param(searchParame);
                    return data;
                }
            },
            columns: [
                {"data": "logisticsId", "className": "hidden"},
                {
                    "data": "logisticsId", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append(row + 1)
                    }
                },
                {"data": "logisticsName"},
                {"data": "principal"},
                {"data": "logisticsContact"},
                {"data": "area"},
                {"data": "joinTime"},
                {"data": "price"},
                {
                    "data": "logisticsId", "createdCell": function (td, cellData, rowData, row, col) {
                        $(td).empty().append(' <a title="编辑" onclick="member_edit(this)" href="javascript:;"  class="btn btn-xs btn-info" ><i class="icon-edit bigger-120"></i></a> \n' +

                            '                    <a title="删除" href="javascript:;"  onclick="member_del(this,\'1\')" \n' +
                            'class="btn btn-xs btn-warning" ><i class="icon-trash bigger-120"></i></a>')
                    }
                },

            ]
        })

        /*搜索*/
        $('#selectbyname').click(function () {
            oTable1.fnUpdate();
        })


        $('table th input:checkbox').on('click', function () {
            var that = this;
            $(this).closest('table').find('tr > td:first-child input:checkbox')
                .each(function () {
                    this.checked = that.checked;
                    $(this).closest('tr').toggleClass('selected');
                });

        });


    });


</script>
<script type="text/javascript">


    /*产品-删除*/
    function member_del(obj, id) {
        layer.confirm('确认要删除吗？', function (index) {
            var ids = $(obj).parent().parent().children("td:eq(0)").text();
            console.log(ids);
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {"id": ids},
                url: '/logisticsxx/delete',
                success: function (data) {
                    alert(data);
                    if(!data.rs){
                        layer.msg(data.msg,{icon:2,time:2000})
                    }
                }
            })
            $(obj).parents("tr").remove();
            parent.layer.msg('已删除!', {icon: 1, time: 1000});
            window.parent.document.getElementById('iframe').contentWindow.location.reload(true);
        });
    }


</script>
